package com.zm.mybatis.damai.mapper;

import com.zm.mybatis.damai.bean.Orders;
import com.zm.mybatis.damai.bean.Product;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface OrdersMapper {
    @Select("select * from dm_orders where id = #{ id }")
    @Results(id = "rm1",
            value = {
                @Result(column = "id" ,property = "id" ,id = true),
                @Result(column = "id",property = "items",
                        many = @Many(
                            select = "com.zm.mybatis.damai.mapper.OrderItemMapper.selectByOid",
                                fetchType = FetchType.LAZY
                        )
                ),
                @Result(column = "uid", property = "uid"),
                @Result(column = "uid", property = "user" ,
                        one = @One(
                                select = "com.zm.mybatis.damai.mapper.UserMapper.selectById",
                                fetchType = FetchType.EAGER
                        )
                )
            }
    )
    Orders selectById(int id);
    @Insert("insert into dm_orders (uid,aid,state) values(#{uid},#{aid},#{state})")
    @Options(useGeneratedKeys = true,keyColumn = "id" ,keyProperty = "id")
    Integer insert(Orders orders);
}
